package com.dqp.cslggroup.UI;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.*;
import androidx.appcompat.widget.AppCompatSeekBar;
import androidx.preference.PreferenceManager;
import cn.carbswang.android.numberpickerview.library.NumberPickerView;
import com.bumptech.glide.Glide;
import com.dqp.cslggroup.R;
import com.dqp.cslggroup.SubjectView.AddCourse;
import com.dqp.cslggroup.Util.GetTimeUtil;
import com.dqp.cslggroup.Util.SharedPreferencesUtil;
import com.dqp.cslggroup.Util.ToastUtil;
import com.dqp.cslggroup.Util.UiUtils;
import com.dqp.cslggroup.bean.*;
import com.dqp.cslggroup.greendao.courseDao;
import com.dqp.cslggroup.greendao.noteDao;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.zhuangfei.timetable.model.Schedule;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

import static com.dqp.cslggroup.UI.MyApplication.getContext;

public class DialogView {
    private static int campus = 1;

    @SuppressLint("SetTextI18n")
    public static void seekBarDialog(Context context, String title, String msg, String unit, getSeekBarLength seekBarLength) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        int length = 0, progress = 0;
        if (unit.contains("px")) {
            length = sp.getInt("lattice_length", 180);
            progress = (length - 100) / 10;
        } else if (unit.contains("sp")) {
            length = sp.getInt("timeSize", 8);
            progress = length - 1;
        } else if (unit.contains("节")) {
            length = sp.getInt("course_jie", 10);
            progress = length;
        }
        editor.apply();
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.seek_bar_dialog, null);
        builder.setView(view);
        final AppCompatSeekBar seekBar = view.findViewById(R.id.seekbar);
        final TextView seekBarDialog_title = view.findViewById(R.id.seekBarDialog_title);
        final TextView seekBarDialog_msg = view.findViewById(R.id.seekBarDialog_msg);
        final TextView seekBarDialog_length = view.findViewById(R.id.seekBarDialog_length);
        final TextView seekBarDialog_unit = view.findViewById(R.id.seekBarDialog_unit);
        if (unit.contains("%")) {
            seekBar.setMax(10);
            progress = sp.getInt("transparency", 3);
            length = progress * 10;
        } else if (unit.contains("r")) {
            seekBar.setMax(13);
            length = sp.getInt("blur", 0);
            progress = length / 2;
        }
        seekBar.setProgress(progress);
        seekBarDialog_title.setText(title);
        seekBarDialog_msg.setText(msg);
        seekBarDialog_length.setText(length + "");
        seekBarDialog_unit.setText(unit);
        Button save = view.findViewById(R.id.btn_save);
        Button cancel = view.findViewById(R.id.btn_cancel);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        seekBarLength.setOnClick(dialog, save, seekBar, seekBarDialog_length);
        cancel.setOnClickListener(v -> dialog.dismiss());
    }

    public interface getSeekBarLength {
        void setOnClick(Dialog dialog, Button save, AppCompatSeekBar seekBar, TextView seekBarDialog_length);
    }


    public static void selectNet(Context context, boolean select, NetEvent clickEvent) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.net_type, null);
        builder.setView(view);
        final RadioGroup radioGroup = view.findViewById(R.id.net_select);
        final RadioButton nei = view.findViewById(R.id.checktv_nei);
        final RadioButton wai = view.findViewById(R.id.checktv_wai);
        nei.setChecked(!select);
        wai.setChecked(select);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        clickEvent.setOnClick(radioGroup, dialog);
    }


    public interface NetEvent {
        void setOnClick(RadioGroup radioGroup, Dialog dialog);
    }

    @SuppressLint("SetTextI18n")
    public static void setCouples(Context context, String cname, int who, saveBg saveBg) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.input_view, null);
        builder.setView(view);
        final EditText name = view.findViewById(R.id.course_title);
        final TextView title = view.findViewById(R.id.tv_title);
        final Button save = view.findViewById(R.id.tv_save);
        final TextView bg = view.findViewById(R.id.course_bg);
        final ImageView img = view.findViewById(R.id.course_img);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
        SharedPreferences.Editor editor = sp.edit();
        String course_name = "";
        String course_bg = "";
        if (who == 0) {
            course_name = sp.getString("me_course_name", cname);
            course_bg = sp.getString("me_course_bg", null);
        } else if (who == 1) {
            course_name = sp.getString("ta_course_name", cname);
            course_bg = sp.getString("ta_course_bg", null);
        }
        title.setText(cname);
        name.setText(course_name + "");
        if (course_bg != null) {
            Drawable drawable = new BitmapDrawable(context.getResources(), course_bg);
            img.setBackground(drawable);
        }
        editor.apply();
        saveBg.saveIt(save, bg, name, dialog, img);
    }

    public interface saveBg {
        void saveIt(Button save, TextView bg, TextView name, Dialog dialog, ImageView img);
    }


    @SuppressLint("RestrictedApi")
    public static boolean examArrangements(Context context, FloatingActionButton floatingActionButton) {
        boolean flag;
        TextView ksmc, kssj, cdmc, kcmc;
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.kao_item, null);
        builder.setView(view);
        ListView listView = view.findViewById(R.id.kao_list);
        ksmc = view.findViewById(R.id.text_xf);
        kssj = view.findViewById(R.id.text_cj);
        cdmc = view.findViewById(R.id.text_jd);
        kcmc = view.findViewById(R.id.text_kc);
        Button button = view.findViewById(R.id.rm_button);
        kcmc.setText("课程名称");
        kcmc.setTextSize(10);
        ksmc.setText("考试名称");
        ksmc.setTextSize(10);
        cdmc.setText("考试地点");
        cdmc.setTextSize(10);
        kssj.setText("考试时间");
        kssj.setTextSize(10);
        button.setText("移除考试周安排");
        flag = examData(listView, context);
        if (flag) {
            Dialog dialog = builder.show();
            UiUtils.setDialogWindowAttr(dialog, context);
            Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
            button.setOnClickListener(arg0 -> {
                SharedPreferences sp;
                SharedPreferences.Editor editor;
                sp = PreferenceManager.getDefaultSharedPreferences(context);
                editor = sp.edit();
                editor.putBoolean("show_kao", false);
                editor.apply();
                dialog.dismiss();
                floatingActionButton.setVisibility(View.GONE);
                MyApplication.getDaoInstant().getExamDao().deleteAll();
            });
        }
        return flag;
    }


    private static boolean examData(ListView listView, Context context) {
        boolean flag = false;
        List<exam> examList = MyApplication.getDaoInstant().getExamDao().loadAll();
        if (examList.size() > 0) {
            ExamAdapter examAdapter = new ExamAdapter(examList, context, true);
            listView.setAdapter(examAdapter);
            flag = true;
        }
        return flag;
    }


    @SuppressLint("RestrictedApi")
    public static void gradeMore(Context context, ArrayList<Grade> dataList) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.grade_more, null);
        builder.setView(view);
        ListView listView = view.findViewById(R.id.grade_more_list);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        GradeMoreAdapter gradeMoreAdapter = new GradeMoreAdapter(dataList, context);
        listView.setAdapter(gradeMoreAdapter);
    }


    @SuppressLint("RestrictedApi")
    public static void PopUps(Context context, String title, String[] titles, int[] logos, clickOn clickOn) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.popups, null);
        builder.setView(view);
        TextView Puptitle = view.findViewById(R.id.Puptitle);
        Puptitle.setText(title);
        GridView gridView = view.findViewById(R.id.pup_grid);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        PupAdapter adapter = new PupAdapter(context, titles, logos);
        gridView.setAdapter(adapter);
        clickOn.Click(gridView, dialog);
    }

    public interface clickOn {
        void Click(GridView gridView, Dialog dialog);
    }

    @SuppressLint("RestrictedApi")
    public static void PopUps(Context context, String title, String[] titles, List<Drawable> drawables, clickOn clickOn) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.popups, null);
        builder.setView(view);
        TextView Puptitle = view.findViewById(R.id.Puptitle);
        Puptitle.setText(title);
        GridView gridView = view.findViewById(R.id.pup_grid);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        PupAdapter adapter = new PupAdapter(context, titles, drawables);
        gridView.setAdapter(adapter);
        clickOn.Click(gridView, dialog);
    }

    public static void courseMore(Context context, List<Schedule> beans, int zhou, boolean couples, refreshTimeTableView refreshTimeTableView) {
        for (Schedule bean : beans) {
            boolean thisWeek;
            List<Integer> integerList = bean.getWeekList();
            thisWeek = integerList.contains(zhou);
            if (thisWeek) {
                int step = bean.getStep();
                int week = bean.getDay();
                int start = bean.getStart();
                int end = start + step - 1;
                String js = start + "-" + end + "节";
                int size, who = 0;
                if (!couples) who = 1;
                List<course> courseList = MyApplication.getDaoInstant().getCourseDao().queryBuilder()
                        .where(courseDao.Properties.Kcmc.eq(bean.getName()))
                        .where(courseDao.Properties.Xqj.eq(bean.getDay()))
                        .where(courseDao.Properties.Jc.eq(js))
                        .where(courseDao.Properties.Xm.eq(bean.getTeacher()))
                        .where(courseDao.Properties.Cdmc.eq(bean.getRoom()))
                        .where(courseDao.Properties.Who.eq(who))
                        .build()
                        .list();
                size = courseList.size();
                if (size > 0) {
                    course course = courseList.get(0);
                    CourseDialog courseDialog = new CourseDialog.Builder(context)
                            .setTitle(course.getKcmc())
                            .setTeacher(course.getXm())
                            .setWeeks(course.getZcd())
                            .setJs(course.getXqjmc() + " 第" + course.getJc())
                            .setRoom(course.getCdmc())
                            .setkhfs(course.getKhfsmc())
                            .setkszc(course.getKcxszc())
                            .setxf(course.getXf())
                            .setEditButton(view -> {
                                Intent intent = new Intent(context, AddCourse.class);
                                intent.putExtra("edit", true);
                                intent.putExtra("couples", couples);
                                intent.putExtra("course", course);
                                context.startActivity(intent);

                            })
                            .setDeleteButton(view -> ToastUtil.showToast("长按删除｡◕ᴗ◕｡"))
                            .setLongDeleteButton(v -> {
                                MyApplication.getDaoInstant().getCourseDao().delete(course);
                                refreshTimeTableView.refresh();
                                ToastUtil.showToast("删除成功！");
                                return true;
                            })
                            .create();
                    courseDialog.show();
                }


            }
        }
    }

    public interface refreshTimeTableView {
        void refresh();
    }

    @SuppressLint("SetTextI18n")
    public static void classNotes(Context context, String courseName, int week, int start, takePhoto photo) {
        List<note> noteList = MyApplication.getDaoInstant().getNoteDao().queryBuilder()
                .where(noteDao.Properties.Name.eq(courseName))
                .where(noteDao.Properties.Start.eq(start))
                .where(noteDao.Properties.Week.eq(week))
                .build().list();
        android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.notes_dialog, null);
        builder.setView(view);
        TextView name = view.findViewById(R.id.note_course_name);
        TextView data = view.findViewById(R.id.note_data);
        EditText noteEd = view.findViewById(R.id.mynote);
        Button save = view.findViewById(R.id.btn_save);
        Button cancel = view.findViewById(R.id.btn_cancel);
        ImageView img = view.findViewById(R.id.img);
        TextView take = view.findViewById(R.id.take_picture);
        name.setText(courseName + "");
        if (noteList.size() > 0) {
            data.setText(noteList.get(0).getData() + "");
            noteEd.setText(noteList.get(0).getText() + "");
            if (noteList.get(0).getImg() != null) {
                Glide.with(context).load(noteList.get(0).getImg()).into(img);
                img.setVisibility(View.VISIBLE);
                img.setOnClickListener(v -> {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setDataAndType(Uri.fromFile(new File(noteList.get(0).getImg())), "image/*");
                    context.startActivity(intent);

                });
            }

        } else {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date date = new Date(System.currentTimeMillis());
            data.setText(simpleDateFormat.format(date));
        }
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        cancel.setOnClickListener(v -> dialog.dismiss());
        photo.getPhoto(save, name, data, noteEd, take, img, dialog, noteList);

    }

    public interface takePhoto {
        void getPhoto(Button save, TextView name, TextView date, EditText text, TextView take, ImageView img, Dialog dialog, List<note> noteList);
    }


    @SuppressLint("RestrictedApi")
    public static void getCourse(Context context, getcourse course) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.get_course, null);
        builder.setView(view);
        NumberPickerView year = view.findViewById(R.id.wp_year);
        NumberPickerView term = view.findViewById(R.id.wp_term);
        year.setMinValue(0);
        year.setMaxValue(7);
        term.setMinValue(0);
        term.setMaxValue(2);
        int month = GetTimeUtil.getMonth();
        int year_nu = GetTimeUtil.getYear();
        if (month < 8 && month >= 2) {
            year.setValue(year_nu - 2017);
            term.setValue(1);
        } else {
            if (month > 7) year_nu++;
            year.setValue(year_nu - 2017);
            term.setValue(0);
        }
        Button save = view.findViewById(R.id.btn_save);
        Button cancel = view.findViewById(R.id.btn_cancel);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        cancel.setOnClickListener(v -> dialog.dismiss());
        course.get(save, year, term, dialog);
    }

    public interface getcourse {
        void get(Button save, NumberPickerView year, NumberPickerView term, Dialog dialog);
    }

    @SuppressLint("SetTextI18n")
    public static void roomElectricity(Context context, TextView rooms) {
        InputMethodManager manager = ((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.roomelectricity, null);
        builder.setView(view);
        TextView tip = view.findViewById(R.id.tip);
        tip.setText("例如：3-203-3号床");
        EditText don = view.findViewById(R.id.room_don);
        EditText ssh = view.findViewById(R.id.room_ssh);
        Spinner spinner = view.findViewById(R.id.bed_spinner);
        Button save = view.findViewById(R.id.btn_save);
        Button cancel = view.findViewById(R.id.btn_cancel);
        RadioButton DH = view.findViewById(R.id.DH_XQ);
        RadioButton DN = view.findViewById(R.id.DN_XQ);
        RadioGroup radioGroups = view.findViewById(R.id.XQ_XZ);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        radioGroups.setOnCheckedChangeListener((group, checkedId) -> {
            if (DN.isChecked()) {
                campus = 1;
                tip.setText("例如：3-203-1号床");
            }
            if (DH.isChecked()) {
                campus = 3;
                tip.setText("例如：12-1028-1号床");
            }
        });
        save.setOnClickListener(v -> {
            if (manager != null)
                manager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            int bedid = spinner.getSelectedItemPosition() + 1;
            String donS = don.getText().toString();
            String sshS = ssh.getText().toString();
            if (donS.length() > 0 && sshS.length() > 2) {
                String room = donS + "-" + sshS + "-" + bedid;
                SharedPreferencesUtil.putStringSp(context, "room", room);
                SharedPreferencesUtil.putStringSp(context, "donS", donS);
                SharedPreferencesUtil.putStringSp(context, "sshS", sshS);
                SharedPreferencesUtil.putStringSp(context, "xq", campus + "");
                SharedPreferencesUtil.putStringSp(context, "bedid", bedid + "");
                rooms.setText(room);
                dialog.dismiss();
            } else ToastUtil.showToast("请输入正确宿舍信息");
        });
        cancel.setOnClickListener(v -> {
            if (manager != null)
                manager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            dialog.dismiss();
        });
    }

    @SuppressLint("SetTextI18n")
    public static void loginDialog(Context context, String title, Login login) {
        InputMethodManager manager = ((InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE));
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.dialog_login, null);
        builder.setView(view);
        TextView tip = view.findViewById(R.id.dialog_login_title);
        tip.setText(title);
        EditText userid = view.findViewById(R.id.dialog_login_userid);
        EditText pwd = view.findViewById(R.id.dialog_login_password);
        CheckBox checkBox = view.findViewById(R.id.remember);
        TextView tipMsg = view.findViewById(R.id.tip);
        tipMsg.setText("云同步账号和密码将会在本应用服务器上存储您的账号和密码，" +
                "以便于用户数据同步，防止出现内网限制的数据访问不正常！" +
                "该选项完全由您自主选择！");
        Button save = view.findViewById(R.id.btn_save);
        Button cancel = view.findViewById(R.id.btn_cancel);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        save.setOnClickListener(v -> {
            if (manager != null)
                manager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            login.login(dialog, userid, pwd, checkBox);
        });
        cancel.setOnClickListener(v -> {
            if (manager != null)
                manager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            dialog.dismiss();
        });
    }

    public interface Login {
        void login(Dialog dialog, EditText userid, EditText pwd, CheckBox checkBox);
    }

    @SuppressLint("SetTextI18n")
    public static void moreConsumer(Context context, String title, List<Consumer> consumerList) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.book_list, null);
        builder.setView(view);
        TextView textView = view.findViewById(R.id.book_title);
        ListView listView = view.findViewById(R.id.book_dqjy);
        TextView textview_1 = view.findViewById(R.id.textview_1);
        TextView textview_2 = view.findViewById(R.id.textview_2);
        TextView textview_3 = view.findViewById(R.id.textview_3);
        TextView textview_4 = view.findViewById(R.id.textview_4);
        textview_1.setText("统计月份");
        textview_2.setText("商场购物");
        textview_3.setText("餐饮消费");
        textview_4.setText("其他消费");
        textView.setText(title);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        ConsumeAdapter adapter = new ConsumeAdapter(consumerList, context);
        listView.setAdapter(adapter);
    }

    @SuppressLint("SetTextI18n")
    public static void moreBook(Context context, String title, List<Borrow> bookBorrowList) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.book_list, null);
        builder.setView(view);
        TextView textView = view.findViewById(R.id.book_title);
        ListView listView = view.findViewById(R.id.book_dqjy);
        TextView textview_1 = view.findViewById(R.id.textview_1);
        TextView textview_2 = view.findViewById(R.id.textview_2);
        TextView textview_3 = view.findViewById(R.id.textview_3);
        TextView textview_4 = view.findViewById(R.id.textview_4);
        textview_1.setText("书名");
        textview_2.setText("借出时间");
        textview_3.setText("限还时间");
        textview_4.setText("是否到期");
        textView.setText(title);
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        BorrowAdapter adapter = new BorrowAdapter(bookBorrowList, context);
        listView.setAdapter(adapter);
    }

    @SuppressLint("SetTextI18n")
    public static void moreEBill(Context context, String title, List<roomElectricity> roomElectricities) {
        final android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context);
        @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.grade_more, null);
        builder.setView(view);
        TextView textView = view.findViewById(R.id.title);
        textView.setText(title);
        ListView listView = view.findViewById(R.id.grade_more_list);
        TextView textview_1 = view.findViewById(R.id.cjfx);
        TextView textview_2 = view.findViewById(R.id.fxbl);
        TextView textview_3 = view.findViewById(R.id.cj);
        textview_1.setText("宿舍");
        textview_2.setText("查询时间");
        textview_3.setText("剩余电量");
        Dialog dialog = builder.show();
        UiUtils.setDialogWindowAttr(dialog, context);
        Objects.requireNonNull(dialog.getWindow()).setBackgroundDrawableResource(android.R.color.transparent);
        EbillAdapter adapter = new EbillAdapter(roomElectricities, context);
        listView.setAdapter(adapter);
    }


}


